<?php
	error_reporting(0);
	include "common.php";
	session_start();
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userName = $_SESSION['userFname'];
	$role = $_SESSION['role'];
	$ID = $_SESSION['id'];
	$supervisor = $_SESSION['supervisor'];
	$userLink = $_SESSION['userLink'];
	$userSql = "SELECT * FROM user WHERE e_id = '$supervisor'";
	$userSqlQuery = mysql_query($userSql);
	$userSqlQueryResult = mysql_fetch_assoc($userSqlQuery);	
	$supervisorFname = $userSqlQueryResult['f_name'];
	$supervisorLname = $userSqlQueryResult['l_name'];	
?>					
<?php
	include "common.php";
	session_start();
	error_reporting(0);	
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userLink = $_SESSION['userLink'];
	if($userLink!="hrpage.php"){
		echo "Sorry, You have no right to visit this page!!";
		exit;
	}
	$userFname = $_SESSION['userFname'];
	$userLname = $_SESSION['userLname'];
	$role = $_SESSION['role'];
	$ID = $_SESSION['id'];
	$supervisor = $_SESSION['supervisor'];

	$leaveType =$_POST['leaveType'];
	$leaveDay = $_POST['day'];
	$leaveMonth = $_POST['month'];
	$leaveYear  = $_POST['year'];
	$leaveDay1 = $_POST['day1'];
	$leaveMonth1 = $_POST['month1'];
	$leaveYear1 = $_POST['year1'];
	$leaveReason = $_POST['leave_reason'];
	
	$leaveFrom = $leaveYear."-".$leaveMonth."-".$leaveDay;
	$leaveTo = $leaveYear1."-".$leaveMonth1."-".$leaveDay1;
	
	//*************** Insert into apply_leave table *********************
	$sql = "INSERT INTO apply_leave (e_id,leave_type,leave_from,leave_to,reason,supervisor,approval)
			VALUES ('$ID','$leaveType','$leaveFrom','$leaveTo','$leaveReason','$supervisor','2')";
			
	$sqlResult = mysql_query($sql);
	
	//**************** Select id From apply_leave Table *********************
	$applyLeave = "SELECT * FROM apply_leave WHERE e_id = '$ID'";
	$applyLeaveSql = mysql_query($applyLeave);
	$applyLeaveSqlResult = mysql_fetch_assoc($applyLeaveSql);
	
	$idofApplyLeave = $applyLeaveSqlResult['id'];
	
	//******************* Insert into notification Table *******************
	$notificationSql = "INSERT INTO notification (reference_id,e_id,supervisor,Type,Reason,Status)
			VALUES ('$idofApplyLeave','$ID','$supervisor','apply_leave','$leaveReason','2')";
			
	$notificationSqlResult = mysql_query($notificationSql);
	
	$notificationSelectSql = "SELECT * FROM user WHERE e_id = '$supervisor'";
	$notificationSelectSqlQuery = mysql_query($notificationSelectSql);
	$notificationSelectSqlQueryResult = mysql_fetch_assoc($notificationSelectSqlQuery);
	
	$supervisorName = $notificationSelectSqlQueryResult['f_name']." ".$notificationSelectSqlQueryResult['l_name'];
	
	$notification = $notificationSelectSqlQueryResult['notification'];
	$notification++;
	
	$updateNotificationSql = "UPDATE user SET notification = '$notification' WHERE e_id = '$supervisor'";
	$updateNotificationSqlQuery = mysql_query($updateNotificationSql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="index.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="hr_attendance.css" />
<link rel="icon" type="image/ico" href="images/favicon.ico"></link> 
<link rel="shortcut icon" href="images/favicon.ico"></link>
<script src="curvycorners.src.js" type="text/javascript"></script>
<script src="login.js" type="text/javascript"></script>
<title><?php echo "Welcome to ".$userFname." ".$userLname; ?></title>
</head>

<body>
<div class="main_div_other">
	<p><img src="images/creato_logo.jpg" /></p>
    <p id="creatobd">www.creatobd.com</p>
    <p id="date"><script>document.write(new_month+" "+new_date+", "+old_date.getFullYear()+" || "+new_day);</script></p>
    <div class="other_page_icons">
    	<div class="new_notification">
        	<img src="images/arrow_up.JPG" /><p>You have a new notification</p>
        </div><!--end of new_notification-->
    	<ul>
        	<a href="hrpage.php"><li><div id="home"></div><p>home</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_employee.php"><li><div id="employee"></div><p>employee</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_onduty.php"><li><div id="onduty"></div><p>on duty</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_attendance.php"><li><div id="attendance"></div><p>attendance</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_leave.php"><li><div id="leave"></div><p>leave</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_notification.php"><li><div id="notification"></div><p>notification</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_black_box_message.php" class="active"><li><div id="blackbox"></div><p>black box</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="#"><li><div id="hrpolicy"></div><p>hr policy</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="index.php"><li><div id="logout"></div><p>log out</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
        </ul>
    </div><!-- end of other_page_icons-->
</div><!-- end of main_div_other-->

<div class="othrpage_1" style="border-bottom:0px !important; height:5px !important;"></div><!-- end of othrpage_1-->

<div>
    	<form method="post" action="hr_blackbox.php">
			<table cellpadding="0" cellspacing="0" class="apply4leave_table hrpage_info_table" align="center">
				<tr>
					<td class="add_user_td1">To Whom Id</td>
					<?php 
						$userSql = "SELECT * FROM user WHERE status=0 ORDER BY f_name";
						$userSqlQuery = mysql_query($userSql);
					?>
					<td><select name="whom">
								<?php
								while ($data = mysql_fetch_assoc($userSqlQuery))
								{
								?>
									<option value="<?php echo $data['e_id']?>"><?php echo $data['f_name']." ".$data['l_name'];?></option>
								<?php 
								}
								?>
						</select></td>
						<td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
				</tr>
					<tr valign="top">
					<td class="add_user_td1">Supervisor</td>
					<td><input type="text" value= "<?php echo $supervisorName; ?>" name="supervisor" style="width:163px;"/></td>
					<td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
				</tr>
				<tr valign="top">
					<td class="add_user_td1">Message</td>
					<td><textarea name="message" cols="58" rows="7"></textarea></td>
					<td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
				</tr>
				<tr><td colspan="3"><p class="submit_button_add_user"><input type="submit" value="submit" /></p></td></tr>
			</table>
		</form>
</div><!-- end of page_content -->
<div class="human_portal">
  		<p>creato human resourse portal</p>
</div><!-- end of human_portal-->
</body>
</html>